package paginator.helpers
{
	import flash.display.DisplayObjectContainer;
	
	import mx.controls.Menu;
	
	public class MenuButtonsCreator
	{
		//---------------------------------------------------------------
		// <------ PUBLIC CONSTS ------>
		//---------------------------------------------------------------
		//{
		
		public static const NEXT_MENU:String = "NextMenu";
		public static const PREVIOUS_MENU:String = "PreviousMenu";
		
		//}
		//---------------------------------------------------------------
		// <------ PRIVATE PROPERTIES ------>
		//---------------------------------------------------------------
		//{
		
		private var _menu:Menu;
		private var _typeMenu:String;
		
		//}
		//---------------------------------------------------------------
		// <------ PUBLIC METHODS ------>
		//---------------------------------------------------------------
		//{
		
		/**
		 * Typ menu
		 * Jezeli 0 - menu obslugujace skok do przodu
		 * Jezeli 1 - menu obslugujace skok do tylu
		 * */
		public function MenuButtonsCreator(typeMenu:String = NEXT_MENU)
		{
			_typeMenu = typeMenu;
		}
		
		public function creatMenu(maximumOptions:int, startValue:int = 0):Menu
		{
			_menu = null;
			
			if (startValue)
			{
				_menu = Menu.createMenu(null, null);
			
				var i:int;
				var valueArr:Array = [];
				var endFactor:int = maximumOptions / 2;
				for (i = 0; i < 4; i++)
				{
					valueArr.push(startValue);
					startValue += startValue;
					if (startValue > endFactor)
					{
						break;
					}
				}
				creatDataForMenu(valueArr);
			}
			
			return _menu;
		}
		
		//}
		//---------------------------------------------------------------
		// <------ PRIVATE METHODS ------>
		//---------------------------------------------------------------
		//{
		
		/**
		 * Odswieza zawartosc menu o nowe dane
		 * 
		 * @param Array valuesArr Wartosci opcji menu
		 * */
		private function creatDataForMenu(valuesArr:Array /*of int*/):void
		{
			if (_menu == null)
			{
				return;
			}
						
			if (valuesArr == null)
			{
				_menu.dataProvider = null;
			}
			else
			{
				var nameLbl:String = "Do przodu o ";
				if (_typeMenu == PREVIOUS_MENU)
				{
					nameLbl = "Wstecz o ";
				}
				
				var obj:Object = null;
				var item:int = 0;
				var dataProviderArr:Array = [];
				for each (item in valuesArr)
				{
					obj = new Object();
					obj.label = nameLbl.concat(item.toString());
					obj.type = "normal";
					switch(_typeMenu)
					{
						case MenuButtonsCreator.NEXT_MENU:
							obj.value = item;
							break;
						case MenuButtonsCreator.PREVIOUS_MENU:
							obj.value = int("-" + item.toString());
							break;
					}
					dataProviderArr.push(obj);
				}
				
				_menu.dataProvider = dataProviderArr;
			}
		}
		//}
	}
}